package com._520it.crm.service.impl;

import com._520it.crm.domain.OrderBill;
import com._520it.crm.mapper.OrderBillMapper;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.OrderBillQueryObject;
import com._520it.crm.query.QueryObject;
import com._520it.crm.service.IOrderBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 呆 on 2017/10/3.
 */
@Service
public class OrderBillServiceImpl implements IOrderBillService {
    @Autowired
    private OrderBillMapper orderBillMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return orderBillMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Long insert(OrderBill orderBill) {
        //新增保单是设置保单的状态为 暂存单
        orderBill.setState(OrderBill.STATE_ZC);
        orderBillMapper.insert(orderBill);
        orderBillMapper.insertRelationsToPro(orderBill.getId(),orderBill.getProductId());
        return orderBill.getId();
    }

    @Override
    public OrderBill selectByPrimaryKey(Long id) {
        return orderBillMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<OrderBill> selectAll() {
        return orderBillMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(OrderBill orderBill) {
        return orderBillMapper.updateByPrimaryKey(orderBill);
    }

    @Override
    public PageResult query(QueryObject qo) {
        Integer totalCount = orderBillMapper.queryforCount(qo);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<OrderBill> data = orderBillMapper.queryforList(qo);
        return new PageResult(totalCount,data);
    }

    @Override
    public PageResult approvalQueryPage(OrderBillQueryObject queryObject) {
        Integer totalCount = orderBillMapper.approvalQueryforCount(queryObject);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<OrderBill> data = orderBillMapper.approvalQueryforList(queryObject);
        return new PageResult(totalCount,data);
    }
    @Override
    public void updateTimeandBaseInfo(OrderBill orderBill) {
        orderBill.setInputUserSn("501");
        orderBillMapper.updateTimeandBaseInfo(orderBill);
    }

    @Override
    public void checkApply(Long orderId ,String remark) {
        orderBillMapper.checkApply(orderId ,remark);
    }


}
